<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
  <head>
    <meta charset="utf-8" />
    <meta name="generator" content="pandoc" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, user-scalable=yes"
    />
    <title>readme</title>
    <style type="text/css">
      code {
        white-space: pre-wrap;
      }
      span.smallcaps {
        font-variant: small-caps;
      }
      span.underline {
        text-decoration: underline;
      }
      div.column {
        display: inline-block;
        vertical-align: top;
        width: 50%;
      }
    </style>
  </head>
  <body>
    <h1 id="practice-exercises-for-external-packages">
      Practice Exercises for external packages
    </h1>
    <h2 id="overview">Overview</h2>
    <p>
      In this section, you’ll have a chance to practice the concepts you’ve
      learned in the videos. First, review the core concepts covered that you’ll
      need to keep in mind. Then go through the exercises below.
    </p>
    <p>
      Remember, these are for your own benefit. Feel free to skip them if you
      don’t find a particular exercise valuable or you get stuck for too long.
    </p>
    <h2 id="core-concepts">Core concepts</h2>
    <h3 id="requirements.txt">requirements.txt</h3>
    <p>
      When working with an application that uses external packages, you need to
      communicate what packages are required for it to run. We do this with a
      <code>requiements.txt</code> file, here is an example:
    </p>
    <pre><code>colorama
prompt_toolkit</code></pre>
    <p>
      Once you have a virtual environment active, you can install all the
      dependencies with this command:
    </p>
    <pre><code>(env) C:\&gt; pip install -r requirements.txt</code></pre>
    <h3 id="virtual-environments">Virtual environments</h3>
    <p>
      Virtual environments are key to having different versions of the same
      library coexisting on your computer. You create one as follows:
    </p>
    <h4 id="macos-linux">macOS / Linux</h4>
    <pre><code>$ python3 –m venv venv
$ . venv/bin/activate</code></pre>
    <h4 id="windows">Windows</h4>
    <pre><code>C:\&gt; python –m venv venv
C:\&gt; venv\scripts\activate</code></pre>
    <h3 id="pip">pip</h3>
    <p>
      Pip is the tool you use on the command line to install and view external
      packages. Here are some examples:
    </p>
    <pre><code>$ pip list
$ pip install colorama
$ pip install -r requirements.txt
$ pip uninstall requests</code></pre>
    <h2 id="exercises">Exercises</h2>
    <p>
      Now it’s your turn. In this practice, go back to the tic tac toe game we
      created back in the chapter on problem solving. Alternatively, if you made
      it through Connect 4, you can work with that one instead. Your job will be
      to:
    </p>
    <ul>
      <li>Create a virtual environment.</li>
      <li>
        Set it as the active python interpreter in PyCharm under
        <code>settings &gt; project &gt; project interpreter</code>.
      </li>
      <li>
        Create a requirements.txt file with <code>colorama</code> as a
        dependency.
      </li>
      <li>Install the requirements with <code>pip</code>.</li>
      <li>Use <code>colorama</code> to add colored output to your game.</li>
    </ul>
  </body>
</html>
